package service

import (
	"ruoyi-go/internal/web/system/domain"
	"strings"
)

// SelectRolePermissionByUserId 根据userId查询所有权限
func SelectRolePermissionByUserId(userId int) []string {
	list := domain.SysRoleModel().SelectRolePermissionByUserId(userId)
	result := make([]string, 0)
	for _, v := range list {
		if len(v.RoleKey) > 0 {
			s := strings.Trim(v.RoleKey, " ")
			result = append(result, strings.Split(s, ",")...)
		}
	}
	return result
}

// SelectRoleNamesByUsername 查询用户的岗位组
func SelectRoleNamesByUsername(username string) string {
	list := domain.SysRoleModel().SelectRoleNamesByUsername(username)
	// 转为字符串拼接后返回
	var builder strings.Builder
	for i, post := range list {
		if i > 0 {
			builder.WriteString(",")
		}
		builder.WriteString(post.RoleName)
	}
	return builder.String()
}
